package com.springcloud.controller;

import com.springcloud.entities.CommonResult;
import com.springcloud.entities.LoginUser;
import com.springcloud.entities.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
@Api(tags = "用户相关API", hidden = true)
public class ConsumerUserController {


	public static final String PAYMENT_URL = "http://CLOUD-PROVIDER-USER-SERVICE"; //加入Eureka后通过注册中心里的服务名来查找

	@Resource
	private RestTemplate restTemplate;

	@ApiOperation(value = "注册", notes = "注册")
	@ApiImplicitParams({})
	@PostMapping("/consumer/user/create")
	public CommonResult<User> createUser(@RequestBody User user) {
		return restTemplate.postForObject(PAYMENT_URL+"/user/create",user,CommonResult.class);
	}
	@ApiOperation(value = "登录", notes = "登录")
	@ApiImplicitParams({})
	@PostMapping("/consumer/user/login")
	public CommonResult<User> login(@RequestBody LoginUser user) {
		return restTemplate.postForObject(PAYMENT_URL+"/user/login",user,CommonResult.class);
	}

	@ApiOperation(value = "找回密码", notes = "找回密码")
	@ApiImplicitParams({})
	@PostMapping("/consumer/user/getLoginPWD")
	public CommonResult<User> getLoginPWD(@RequestBody User user) {
		return restTemplate.postForObject(PAYMENT_URL+"/user/getLoginPWD",user,CommonResult.class);
	}

	@RequestMapping(value = "/swagger")
	public String index() {
		System.out.println("swagger-ui.html");
		return "redirect:swagger-ui.html";
	}

}
